/****************************************************************************************
 *
 * File Name: kf_it.c
 * Project Name: KF32A156
 * Version: v1.0
 * Date: 2021-05-17- 09:13:03
 * Author: dell
 * 
 ****************************************************************************************/
#include "kf32a1x6_canfd.h"

extern uint8_t Receive_Flag;
extern Canfd_MailboxHeaderType  Receive_Canfd_MailboxHeader;

//Note:
//*****************************************************************************************
//                                 NMI Interrupt Course
//*****************************************************************************************	
void __attribute__((interrupt)) _NMI_exception (void)
{	

}

//*****************************************************************************************
//                               HardFault Interrupt Course
//*****************************************************************************************	

void __attribute__((interrupt)) _HardFault_exception (void)
{

}

//*****************************************************************************************
//                               StackFault Interrupt Course
//*****************************************************************************************	
void __attribute__((interrupt)) _StackFault_exception (void)
{

}

//*****************************************************************************************
//                               SVC Interrupt Course
//*****************************************************************************************	
void __attribute__((interrupt)) _SVC_exception (void)
{

}

//*****************************************************************************************
//                              SoftSV Interrupt Course
//*****************************************************************************************	
void __attribute__((interrupt)) _SoftSV_exception (void)
{

}

//*****************************************************************************************
//                              SysTick Interrupt Course
//*****************************************************************************************	
void __attribute__((interrupt)) _SysTick_exception (void)
{
	
}


//*****************************************************************************************
//                              CANFD6 Interrupt Course
//*****************************************************************************************
void __attribute__((interrupt)) _CANFD6_exception (void)
{
	uint8_t Rmc_count = 0x00;
	Can_Controller_InterruptFlagType Can_Controller_InterruptFlag;
	volatile Kf32a_Canfd_Reg *ControllerRegPtr = (Kf32a_Canfd_Reg *)Can_m_ControllersInfo[CANfd6].BaseAddress;
	Can_m_FdGetIntFlag(CANfd6, &Can_Controller_InterruptFlag, &Rmc_count);
	Can_m_FdClearIntFlag(CANfd6, &Can_Controller_InterruptFlag,Rmc_count);
	if(Can_Controller_InterruptFlag.RxIntFlag == 0x01)
	{
		if(Can_m_FdGetMailBoxState(CANfd6,Mailbox_0) == MAIL_RECEIVE_SUCCESS)
		{
			/* Read recevie mailbox information and reinitialize mailbox code */
			if(Can_m_FdMailBox_Read(CANfd6,Mailbox_0,&Receive_Canfd_MailboxHeader,MAIL_RECEIVE) == CAN_OK)
			{
				Receive_Flag++;
			}

		}
	}
}



